<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="f()">
<div>结果：</div>
</body>

<script>
  function f() {
    let i = document.querySelector("input")
    let d = document.querySelector("div")
      //判断用户输入的内容是否时数值
      if (isNaN(i.value)){
          d.innerText = "输入有误!"
          return
      }
    d.innerText ="结果："+i.value*i.value;
  }
</script>

</html>